package com.demoproject.demo.service;

import com.alibaba.fastjson.JSONObject;
import com.demoproject.demo.dj.mapper.StockMapper;
import com.demoproject.demo.dj.mapper.StockOrderMapper;
import com.demoproject.demo.dj.pojo.Stock;
import com.demoproject.demo.dj.pojo.StockOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhanglong
 */
@Service
public class StockService {
    @Resource
    private StockMapper stockMapper;
    @Resource
    private StockOrderMapper stockOrderMapper;

    private Logger logger= LoggerFactory.getLogger(this.getClass());


    public void service()  {
        try {

            List<Stock> stocks = stockMapper.selectByCount();
            logger.info("查询出来的商品:{}", JSONObject.toJSONString(stocks));
            Thread.sleep(10);
            if (stocks.size() < 0) {
                throw new Exception();
            }
            stockMapper.updateByCount();
            StockOrder stockOrder = new StockOrder();
            stockOrder.setSid(1);
            stockOrder.setName("aaa");
            stockOrderMapper.insert(stockOrder);
        }catch (Exception e){
            logger.error("报错:{0}", e);
        }
    }
}
